package com.yunhai.xc.user.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.yunhai.xc.user.domain.User;

@Controller
@RequestMapping("/lina")
public class LoginController {
	@PostMapping("/login")
	public String login(User user) {
		Subject subject = SecurityUtils.getSubject();
		UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(),
				new Md5Hash(user.getPassword(), user.getUsername()).toString());
		subject.login(token);
		return "shiro/index";

	}

	@RequestMapping("shiro")
	public String shiro() {
		return "user/shiro";
	}
}
